# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Jürgen Pfeifer <juergen@familiepfeifer.de>

_realname=qrupdate
pkgbase=mingw-w64-${_realname}-svn
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}-svn
pkgver=r28
pkgrel=4
pkgdesc="qrupdate is a Fortran library for fast updates of QR and Cholesky decompositions (mingw-w64)"
arch=('any')
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
url="https://qrupdate.sourceforge.io/"
options=('strip' 'staticlibs')
license=('GPL' 'LGPL')
makedepends=("subversion"
             "${MINGW_PACKAGE_PREFIX}-gcc-fortran")
depends=("${MINGW_PACKAGE_PREFIX}-openblas")
source=("${_realname}::svn+https://svn.code.sf.net/p/qrupdate/code")
sha256sums=('SKIP')

pkgver() {
  cd "${srcdir}/${_realname}"
  local ver="$(svnversion)"
  printf "r%s" "${ver//[[:alpha:]]}"
}

build() {
  mkdir -p ${srcdir}/build-${CARCH} && cd ${srcdir}/build-${CARCH}
  cp -pR ../${_realname}/* .
  make FPICFLAGS="" lib
  gfortran -shared -o lib${_realname}.dll -Wl,--out-implib,lib${_realname}.dll.a src/*.o -lopenblas -lgfortran
}

package() {
  cd ${srcdir}/build-${CARCH}
  mkdir -p ${pkgdir}${MINGW_PREFIX}/bin
  mkdir -p ${pkgdir}${MINGW_PREFIX}/lib
  cp -pf lib${_realname}.dll ${pkgdir}${MINGW_PREFIX}/bin
  cp -pf lib${_realname}*.a ${pkgdir}${MINGW_PREFIX}/lib
  mkdir -p ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}
  cp -pf ${srcdir}/${_realname}/COPYING* \
    ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}
}
